﻿define(['admin/app', 'service/admin/tokenUpGradeService'], function (app) {
    "use strict";
    app.controller('tokenUpGradeController', function ($scope, $state, $stateParams, $uibModal,$location, utils, w5cValidator, tokenUpGradeService, baseService) {
        $scope.list = {};
        $scope.query = { page: 1, size: 20, name: '' };
        $.extend($scope.query, $stateParams);
        var methods = {
            search: function () {
                tokenUpGradeService.gets($scope.query).success(function (response) { $scope.model = response.data; });
            },
            search_page: function (page) {
                $scope.query.page = page;
                $location.search('page', $scope.query.page);
            },
            edit: function () {
                tokenUpGradeService.get({ id: $stateParams.id }).success(function (response) {
                    $scope.model = response.data;
                });
            },
            open_img: function (model) {
                $uibModal.open({
                    templateUrl: 'imgshow.html',
                    controller: 'imgshow_Ctrl',
                    resolve: {
                        model: function () {
                            return model;
                        }
                    }
                }).result.then(function (model) {

                });
            },
            goBack: function () {
                history.back();
            },
            tokenUpGradeMaker: function () {
                tokenUpGradeService.getTokenUpGradeMakerPageList($scope.query).success(function (response) {
                    $scope.model = response.data;
                });
            },
            tokenUpGradeMaker_page: function (page) {
                $scope.query.page = page;
                methods.tokenUpGradeMaker('page', $scope.query.page);
            },
            setTokenUpGradeMakerProcessed: function (chargeId) {
                var modal = utils.confirm({ msg: "是否将该记录设为已处理", ok: "确定", cancel: "取消" });
                modal.result.then(function () {
                    tokenUpGradeService.setTokenUpGradeMakerProcessed(chargeId).success(function () {
                        methods.tokenUpGradeMaker();
                    });
                })
            },
        };

        angular.extend($scope, methods);
        if ($state.includes('app.tokenupgrade.detail')) {
            methods.edit();
        } else if ($state.includes('app.token_up_grade.tokenUpGradeMaker')) {
            methods.tokenUpGradeMaker_page();
        }  else {
            methods.search();
        }
    });
    app.controller('imgshow_Ctrl', function ($scope, $uibModalInstance, $uibModal, utils, tokenUpGradeService, model) {
        $scope.img_url = model;

        $scope.cancel = function () {
            $uibModalInstance.dismiss('cancel');
        };
    });
});